
package com.insigma.business.qrcode.common.converter;


import com.insigma.business.qrcode.soldier.dto.SoldierBSearcher;
import com.insigma.business.qrcode.soldier.dto.SoldierDTO;
import com.insigma.business.qrcode.soldier.entity.SoldierDO;
import com.insigma.business.qrcode.soldier.request.SoldierInsertRequest;
import com.insigma.business.qrcode.soldier.request.SoldierSearchRequest;
import com.insigma.business.qrcode.soldier.request.SoldierUpdateRequest;
import org.springframework.beans.BeanUtils;

import java.util.List;


public class SoldierProviderConverter extends AbstractConverter<SoldierDTO, SoldierDO> {

    private final static SoldierProviderConverter soldierConverter = new SoldierProviderConverter();

    private SoldierProviderConverter(){}

    
    public static SoldierBSearcher convertRequestSO2Searcher(final SoldierSearchRequest request){
        final SoldierBSearcher soldierBSearcher = new SoldierBSearcher(request.getPageNo(),
        request.getPageSize(),request.getSortKeyValueJoint());
        BeanUtils.copyProperties(request,soldierBSearcher);
        return soldierBSearcher;
    }

    
    public static SoldierDO convertRequestUO2DO(final SoldierUpdateRequest soldierUpdateRequest) {
        final SoldierDO soldierDO = new SoldierDO();
        BeanUtils.copyProperties(soldierUpdateRequest,soldierDO);
        
        return soldierDO;
    }

    
    public static SoldierDO convertRequestIO2DO(final SoldierInsertRequest soldierInsertRequest) {
        final SoldierDO soldierDO = new SoldierDO();
        BeanUtils.copyProperties(soldierInsertRequest,soldierDO);
        return soldierDO;
    }

    
    public static List<SoldierDTO> convertResponseDOList2DTOList(final List<SoldierDO> soldierDOList){
        return soldierConverter.convertGenericResponseDOList2DTOList(soldierDOList);
    }

    
    public static SoldierDTO convertResponseDO2DTO(final SoldierDO soldierDO){
        return soldierConverter.convertGenericResponseDO2DTO(soldierDO);
    }

    
    @Override
    protected SoldierDTO doConvertResponseDO2DTO(SoldierDO soldierDO) {
        final SoldierDTO soldierDTO = new SoldierDTO();
        try {
            BeanUtils.copyProperties(soldierDO, soldierDTO);
        }catch(RuntimeException be){
            
            return null;
        }
        return soldierDTO;
    }

}
